﻿        <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#mahoadon").keypress(function () {
                var key = event.keyCode;
                if (key == 13) {
                    var tg = $("#mahoadon").val();
                    if (tg == "0") {
                        $("#mavattu").focus();
                        return false;
                    }
                    __doPostBack('', '');
                }
            });


            /*$(".vt1").keypress(function () {
                var key = event.keyCode;
                if (key == 13) {
                    var a = enter(this, "inputindex", "thanhtoan", 1, 2);
                    return false;
                }
            });*/

            $(".hd").keypress(function () {
                var key = event.keyCode;
                if (key == 13) {
                    var a = nextinput(this);
                    return false;
                }
            });

            //enter(this, attr, id button, chi so xac dinh null, chi so xac dinh postback)
           /* function enter(a, b, c, d, e) {
                //ten class
                var className = $(a).attr("class");


                //tong so class
                var max = document.querySelectorAll("input." + className).length;
                //so tu tu cua textbox hien tai
                var temp = parseInt($(a).attr(b));

                if (temp == e) {
                    var tg = $("." + className + "[" + b + "=" + e + "]").val();

                    if (tg == "") {

                        return false;
                    }
                    __doPostBack('', '');
                }

                if (temp == d) {
                    tg = $("." + className + "[" + b + "=" + d + "]").val();
                    if (tg == "") {
                        $("#" + c).focus();
                        return false;
                    }
                }

                if (temp == max) {
                    $("#" + c).focus();
                    return false;
                }
                temp = temp + 1;
                $("." + className + "[" + b + "=" + temp + "]").focus();
                return false;
            }
            */
            // tinh gia khi thay doi so luong
            $('#gv input').change(function () {
                var $a = $(this).parent().next();
                var $b = $(this).parent().next().next().children();
                $b.val($a.text() * $(this).val());
            });

        });

        //check ton tai trong co so du lieu
        function checkdata(_this, inputnext) {

            //_this doi tuong gay ra su kien
            //textbox tiep theo duoc focus

            var key = event.keyCode;
            if (key == 13) {
                var txt = $(_this).val();
                
                //kiem tra co ton tai trong csdl ?
                $.ajax({ url: "Default5.aspx",
                    type: "post",
                    data: "data=" + txt + "&keydata=" + $(_this).attr("keydata"),
                    async:false,
                    success: function (data) {
                        $(_this).val(data);
                    }


                });
                if ($(_this).val() == "") {
                    window.open('popup.aspx?&Datatable=' + $(_this).attr("keydata") + '&Text=' + txt + '&buttomid=&textboxid=' + $(_this).attr("id") + '&textboxnext=' + inputnext, 'a', 'width=500,height=500,status=1');
                    
               }
               
                    $("#" + inputnext).focus();
               
               
            }
        }


        function nextinput(_this) {
          
            //ten class
            var className = $(_this).attr("class");
            

            //tong so class name=className
            var max = document.querySelectorAll("input." + className).length;
            //so tu tu cua textbox hien tai
            var temp = parseInt($(_this).attr("inputindex"));

            temp = temp + 1;
            //$(".hd[inputindex=4]").focus();
            //alert("." + className + "[inputindex=" + temp + "]");
            $("." + className + "[inputindex=" + temp + "]").focus();
        }
      
    </script>
</head>
<body>
    <form id="form1" runat="server" submitdisabledcontrols=true>
    <p><center> Lập hóa đơn</center></p>
    <div>
       <asp:Label ID="lbtrangthai" runat=server></asp:Label>
       <fieldset><legend>nhập thông tin hóa đơn</legend>
        <table>
            <tr>
                <td>Ma Khach</td>
                <td><asp:TextBox ID="makhach"  hdindex=1 runat=server keydata=4 onkeypress="checkdata(this,'manhanvien')"></asp:TextBox></td>
                <td> Ma Nhan Vien</td>
                <td><asp:TextBox ID="manhanvien"  hdindex=4 runat=server keydata=1 Databt="thanhtoan" onkeypress="checkdata(this,'soluonghd')" ></asp:TextBox></td>
            </tr>
            <tr>
                <td> So Luong</td>
                <td><asp:TextBox ID="soluonghd" CssClass="hd" inputindex=3 DataType="integer" runat=server ></asp:TextBox></td>
                <td>So Tien</td>
                <td><asp:TextBox ID="sotienhd" CssClass="hd" inputindex=4 DataType="integer" runat=server></asp:TextBox></td>
            </tr>
            
        </table></fieldset>
        <fieldset><legend>nhập mã vật tư</legend>
            <table>
                <tr>
                    <td> Ma Vat Tu</td>
                    <td> <asp:TextBox ID="mavattu" CssClass=hd runat=server inputindex=5 keydata="3" 
                            ontextchanged="mavattu_TextChanged" AutoPostBack=true></asp:TextBox></td>
                </tr>
            </table>
        </fieldset>

       
        <asp:GridView ID="gv" runat=server AutoGenerateColumns="false">
            <Columns>
               <asp:BoundField DataField="Mavt" HeaderText="vat tu" />
            
               <asp:TemplateField HeaderText="Số lượng"  >
                    <ItemTemplate>
                        <asp:TextBox ID="txtsoluong" soluongindex=<%#index() %> runat="server" CssClass=tb1 bt=btThanhtoan DataType="integer" Text=<%#Eval("Soluong") %> style="text-align:right"  ></asp:TextBox>
                    </ItemTemplate>
               </asp:TemplateField>
                  <asp:BoundField DataField="Dongia" HeaderText="dongia" ItemStyle-HorizontalAlign="Right" />
               <asp:TemplateField HeaderText="So tien">
                    <ItemTemplate>
                        <asp:TextBox ID="txtsotien" runat="server" Text=<%#Eval("Sotien") %> CssClass="txtsotien" style="text-align:right"></asp:TextBox>
                    </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="Xóa">
                    <ItemTemplate>
                        <asp:LinkButton ID="btxua" runat="server" Text="xoa" CommandName="Delete"></asp:LinkButton>
                    </ItemTemplate>
               </asp:TemplateField>
            </Columns>
        </asp:GridView>
            <asp:Button ID="thanhtoan" Text="Thanh toan" runat=server  UseSubmitBehavior=false
            onclick="thanhtoan_Click1" />
            
           <a href="Default3.aspx?Hoa_don_id=0">Thêm mới</a>
           <br />
        <asp:Label ID="lbloi" runat=server></asp:Label>
    </div>
    </form>
</body>
</html>
